﻿///***************************************************************
/// 시  스  템 : Updms.Crd
/// 단위시스템 : CRD
/// 계      층 : Presentation Layer
/// 프로그램명 : Crd1010m
/// 파  일  명 : Crd1010m.aspx.cs
/// 설      명 : 카드기본정보
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2008-07-17 송시명   최초 작성
/// CH002  2008-10-09 송시명   결제일범위 추가
///***************************************************************
using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using SMFramework.Data;
using SMFramework.Utility;
using SMFramework.Web.UI.WebControls.Page;

using Base.AppFramework.Web.UI.CommandBar;
using Base.Dac;

using Updms.Crd.Exe;
using Updms.Mny.Exe;


namespace Updms.Crd
{
	public partial class Crd1010m : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		public static readonly string PID = "Crd1010m";
		public static readonly string gs_path_info = "/updms/Crd/" + PID + ".aspx";
	
		Global global = new Global();
		CommCode.Com com = new CommCode.Com(LANG_SET);
		CommCode.Crd crd = new CommCode.Crd(LANG_SET);

		//페이징
		private int li_cur_page, li_row_count, li_st_page, li_ed_page;
		protected int li_page_size = GRID_PAGESIZE;// 한 페이지에 출력될 행의수

		//검색
		protected string kw1 = "";	// 검색1
		protected string kw2 = "";	// 검색2
		protected string kw3 = "";	// 검색3

		//메뉴 선택값
		protected string gs_sm = "";

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
				SearchProcess();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetClientScript();
			SetSearchUseYn();
			SetIssueCo();
			SetPaymntBank();
			SetPamntDtRegionDiv();
			SetPamntDtRegion();
			SetUseYn();
			SetSearchParameter();
		}

		#endregion
		
		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region SetClientScript

		private void SetClientScript()
		{
			txt_limit_use.Attributes.Add("onkeyup", "form1.txt_limit_use.value=addComma(form1.txt_limit_use.value);");
			txt_limit_cash.Attributes.Add("onkeyup", "form1.txt_limit_cash.value=addComma(form1.txt_limit_cash.value);");

			//onKeyPress이벤트 (엔터검색)
			txt_search_card_nm.Attributes.Add("onkeypress", "enterSearch(event)");
			txt_search_card_num.Attributes.Add("onkeypress", "enterSearch(event)");
			ddl_search_use_yn.Attributes.Add("onkeypress", "enterSearch(event)");
		}

		#endregion

		#region SetInit, SetSearchParameter, ShowKeywordLabel

		//초기값설정
		private void SetInit()
		{
			lbl_search_flag.Text = "INIT";
			if (Request.QueryString["page"] == null || int.Parse(Request.QueryString["page"]) == 1)
			{
				li_cur_page = 1;
				li_st_page = 0;
				li_ed_page = li_page_size;
			}
			else
			{
				li_cur_page = int.Parse(Request.QueryString["page"]);
				li_st_page = (int.Parse(Request.QueryString["page"]) - 1) * li_page_size;
				li_ed_page = li_st_page + li_page_size;
			}

			gs_sm = (Request.QueryString["sm"] == null || Request.QueryString["sm"].Trim().Length != 7)
					? global.GetDirDepth(PID) : Request.QueryString["sm"].ToString();
		}

		//검색파라미터
		private void SetSearchParameter()
		{
			switch (lbl_search_flag.Text.Trim().ToUpper())
			{
				case "INIT":
					if (String.IsNullOrEmpty(Request.QueryString["kw1"]))	// url에 값이 없으면
					{
						kw1 = txt_search_card_nm.Text.Trim();
					}
					else
					{
						kw1 = Server.UrlDecode(Request.QueryString["kw1"]);
						txt_search_card_nm.Text = kw1;
					}
					if (String.IsNullOrEmpty(Request.QueryString["kw2"]))	// url에 값이 없으면
					{
						kw2 = txt_search_card_num.Text.Trim();
					}
					else
					{
						kw2 = Server.UrlDecode(Request.QueryString["kw2"]);
						txt_search_card_num.Text = kw2;
					}
					if (String.IsNullOrEmpty(Request.QueryString["kw3"]))	// url에 값이 없으면
					{
						kw3 = ddl_search_use_yn.SelectedValue;
					}
					else
					{
						kw3 = Server.UrlDecode(Request.QueryString["kw3"]);
						ddl_search_use_yn.SelectedValue = kw3;
					}
					break;
				case "SEARCH":
					kw1 = txt_search_card_nm.Text.Trim();
					kw2 = txt_search_card_num.Text.Trim();
					kw3 = ddl_search_use_yn.SelectedValue;
					break;
			}
		}

		//검색키워드
		private void ShowKeywordLabel()
		{
			lbl_search_keyword.Text = kw1 + " / " + kw2 + " / " + kw3;
		}

		#endregion

		#region 마스터 Method (SetSearchUseYn)

		//사용여부
		private void SetSearchUseYn()
		{
			com.SetUseYn(ddl_search_use_yn);
			ddl_search_use_yn.Items.Insert(0, new ListItem(DDL_SELECT, ""));
		}

		#endregion

		#region 디테일 Method (SetNewCardCd, SetIssueCo, SetPaymntBank, SetPamntDtRegion, SetUseYn)

		//신규카드코드
		private void SetNewCardCd()
		{
			Crd1010m_NT _Crd1010m_NT = new Crd1010m_NT();
			lbl_card_cd.Text = _Crd1010m_NT.GetNewCardCd();
		}

		//발급기관
		private void SetIssueCo()
		{
			crd.SetIssueCo(ddl_issue_co);
		}

		//결재은행
		private void SetPaymntBank()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();
			Mny1010m_NT _Mny1010m_NT = new Mny1010m_NT();

			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			lo_ds.Merge(_Mny1010m_NT.GetPaymntBank(lo_dp));

			ddl_accnt_num.Items.Clear();
			ddl_accnt_num.DataSource = lo_ds;
			ddl_accnt_num.DataMember = "UPDMS_MNY_BNK_ACCNT_INFO";
			ddl_accnt_num.DataTextField = "Text";
			ddl_accnt_num.DataValueField = "Value";
			ddl_accnt_num.DataBind();
			ddl_accnt_num.Items.Insert(0, new ListItem(DDL_SELECT, ""));
		}

		//결제일범위구분
		private void SetPamntDtRegionDiv()
		{
			crd.SetPamntDtRegionDiv(ddl_mass_st_div);
			crd.SetPamntDtRegionDiv(ddl_mass_ed_div);
			crd.SetPamntDtRegionDiv(ddl_cash_st_div);
			crd.SetPamntDtRegionDiv(ddl_cash_ed_div);
		}
		
		//결제범위 - 일자
		private void SetPamntDtRegion()
		{
			//01~31
			for (int i = 1; i <= 31; i++)
			{
				string ls_day = i.ToString();
				ddl_mass_st_dt.Items.Add(new ListItem(ls_day, ls_day));
				ddl_mass_ed_dt.Items.Add(new ListItem(ls_day, ls_day));
				ddl_cash_st_dt.Items.Add(new ListItem(ls_day, ls_day));
				ddl_cash_ed_dt.Items.Add(new ListItem(ls_day, ls_day));
			}

			//32는 말일
			ddl_mass_st_dt.Items.Insert(31, new ListItem("말일", "32"));
			ddl_mass_ed_dt.Items.Insert(31, new ListItem("말일", "32"));
			ddl_cash_st_dt.Items.Insert(31, new ListItem("말일", "32"));
			ddl_cash_ed_dt.Items.Insert(31, new ListItem("말일", "32"));
		}

		//사용여부
		private void SetUseYn()
		{
			com.SetUseYn(rbl_use_yn);
		}
		
		#endregion

		#region CRUD (SelectProcess, InsertProcess, UpdateProcess, DeleteProcess, SearchProcess)

		//조회
		private void SelectProcess()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();
			int li_page_count;

			//검색
			lo_dp.AddProperty("ls_card_nm", typeof(string), kw1);
			lo_dp.AddProperty("ls_card_num", typeof(string), kw2);
			lo_dp.AddProperty("ls_use_yn", typeof(string), kw3);

			using (Crd1010m_NT _Crd1010m_NT = new Crd1010m_NT())
			{
				li_row_count = _Crd1010m_NT.GetSearchCount(lo_dp);	// 검색된 행수
				li_page_count = (int)((li_row_count - 1) / li_page_size) + 1;	// 총페이지수 계산

				//모두보기/페이징
				lo_dp.AddProperty("li_st_page", typeof(Int32), (cb_list_all.Checked) ? 0 : li_st_page);
				lo_dp.AddProperty("li_ed_page", typeof(Int32), (cb_list_all.Checked) ? li_row_count : li_ed_page);
				lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);
				lbl_page.Visible = !cb_list_all.Checked;

				lo_ds.Merge(_Crd1010m_NT.SelectProcess(lo_dp));

				GridView1.DataSource = lo_ds;
				GridView1.DataBind();

				Pager pager = new Pager(this, ref lbl_page);
				pager.PageNavigation(
					li_cur_page,
					li_page_count,
					gs_path_info + "?sm=" + gs_sm + "&kw1=" + Server.UrlEncode(kw1) + "&kw2=" + Server.UrlEncode(kw2) + "&kw3=" + Server.UrlEncode(kw3) + "&page=");

				//결과출력(키워드, 검색행수)
				ShowKeywordLabel();
				lbl_result_count.Text = li_row_count.ToString("#,###,##0");
			}
		}

		//저장
		private void InsertProcess()
		{
			using (Crd1010m_RT _Crd1010m_RT = new Crd1010m_RT())
			{
				int li_return = _Crd1010m_RT.InsertProcess(SetValue());
				string ls_msg_id = (li_return > 0) ? "MSG_INF_007" : "MSG_ERR_105";	//저장되었습니다:저장할 수 없습니다
				CallMsgBoxInAjax(ls_msg_id);

				SearchProcess();
			}
		}

		//수정
		private void UpdateProcess()
		{
			using (Crd1010m_RT _Crd1010m_RT = new Crd1010m_RT())
			{
				int li_return = _Crd1010m_RT.UpdateProcess(SetValue());
				string ls_msg_id = (li_return > 0) ? "MSG_INF_006" : "MSG_ERR_104";	//수정되었습니다:수정할 수 없습니다
				CallMsgBoxInAjax(ls_msg_id);
				
				SearchProcess();
			}
		}

		//삭제
		private void DeleteProcess(string ls_xml)
		{
			using (Crd1010m_RT _Crd1010m_RT = new Crd1010m_RT())
			{
				int li_return = _Crd1010m_RT.DeleteProcess(ls_xml);
				string ls_msg_id = (li_return > 0) ? "MSG_INF_004" : "MSG_ERR_103";	//삭제되었습니다:삭제할 수 없습니다
				CallMsgBoxInAjax(ls_msg_id);

				SearchProcess();
			}
		}

		//검색
		private void SearchProcess()
		{
			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();
			ClearValue();
			SelectProcess();
			SetNewCardCd();
		}

		#endregion

		#region SetValue, ClearValue

		//SetValue
		private DataPack SetValue()
		{
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("Seq", typeof(string), lbl_pk.Text);

			lo_dp.AddProperty("Card_Cd",		typeof(string), lbl_card_cd.Text);
			lo_dp.AddProperty("Card_Nm",		typeof(string), txt_card_nm.Text);
			lo_dp.AddProperty("Card_Num",		typeof(string), txt_card_num.Text);
			lo_dp.AddProperty("Cvc_Num",		typeof(string), ConversionUtil.DefaultValue(txt_cvc_num.Text));
			lo_dp.AddProperty("Valid_Ym",		typeof(string), ConversionUtil.DefaultValue(txt_valid_ym.Text));
			lo_dp.AddProperty("Limit_Use",		typeof(string), ConversionUtil.DefaultValue(txt_limit_use.Text, "0"));
			lo_dp.AddProperty("Limit_Cash",		typeof(string), ConversionUtil.DefaultValue(txt_limit_cash.Text, "0"));
			lo_dp.AddProperty("Issue_Co",		typeof(string), ddl_issue_co.SelectedValue);
			lo_dp.AddProperty("Accnt_Num",		typeof(string), ddl_accnt_num.SelectedValue);
			lo_dp.AddProperty("Use_Yn",			typeof(string), rbl_use_yn.SelectedValue);
			lo_dp.AddProperty("Mass_St_Div",	typeof(int),	ddl_mass_st_div.SelectedValue);
			lo_dp.AddProperty("Mass_St_Dt",		typeof(int),	ddl_mass_st_dt.SelectedValue);
			lo_dp.AddProperty("Mass_Ed_Div",	typeof(int),	ddl_mass_ed_div.SelectedValue);
			lo_dp.AddProperty("Mass_Ed_Dt",		typeof(int),	ddl_mass_ed_dt.SelectedValue);
			lo_dp.AddProperty("Cash_St_Div",	typeof(int),	ddl_cash_st_div.SelectedValue);
			lo_dp.AddProperty("Cash_St_Dt",		typeof(int),	ddl_cash_st_dt.SelectedValue);
			lo_dp.AddProperty("Cash_Ed_Div",	typeof(int),	ddl_cash_ed_div.SelectedValue);
			lo_dp.AddProperty("Cash_Ed_Dt",		typeof(int),	ddl_cash_ed_dt.SelectedValue);
			lo_dp.AddProperty("Attach_File1",	typeof(string), ConversionUtil.DefaultValue(lbl_attach_file1.Text));
			lo_dp.AddProperty("Attach_File1_Size", typeof(string), ConversionUtil.DefaultValue(lbl_attach_file1_size.Text, "0"));
			lo_dp.AddProperty("Create_User",	typeof(string), USER_ID);
			lo_dp.AddProperty("Create_Dt",		typeof(string), "");
			lo_dp.AddProperty("Update_User",	typeof(string), USER_ID);
			lo_dp.AddProperty("Update_Dt",		typeof(string), "");

			return lo_dp;
		}
		
		//ClearValue
		private void ClearValue()
		{
			lbl_pk.Text = "";
			h_no.Value = "";
			lbl_card_cd.Text = "";
			txt_card_nm.Text = "";
			txt_card_num.Text = "";
			txt_cvc_num.Text = "";
			txt_valid_ym.Text = "";
			txt_limit_use.Text = "";
			txt_limit_cash.Text = "";
			ddl_issue_co.SelectedIndex = 0;
			ddl_accnt_num.SelectedIndex = 0;
			rbl_use_yn.SelectedIndex = 0;
			ddl_mass_st_div.SelectedIndex = 0;
			ddl_mass_st_dt.SelectedIndex = 0;
			ddl_mass_ed_div.SelectedIndex = 0;
			ddl_mass_ed_dt.SelectedIndex = 0;
			ddl_cash_st_div.SelectedIndex = 0;
			ddl_cash_st_dt.SelectedIndex = 0;
			ddl_cash_ed_div.SelectedIndex = 0;
			ddl_cash_ed_dt.SelectedIndex = 0;
			lbl_attach_file1.Text = "";
			lbl_attach_file1_size.Text = "";
			ibtn_delete_attach_file1.Visible = false;
		}

		#endregion

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_BASE);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
					//사용권한별 버튼처리
					PagePreRender.SetVisibleCtrl(this, access.CheckPgmUsingGrant(USER_DIV, PID), access.GetVisibleCtrl(PID));
				}
			}
			ChangePageMode();
		}

		// ChangePageMode
		private void ChangePageMode()
		{
			SetGridViewHeader(global.GetColumnListByPgmId(PID, LANG_SET));
		}

		#endregion

		#region File (UploadFile, DeleteFile)

		//첨부파일업로드
		private void UploadFile()
		{
			string ls_file_name = PID + "_";
			string upload_path = FILE_PATH_UPLOAD + "\\";

			HttpFileCollection hfc = Request.Files;
			for (int i = 0; i < hfc.Count; i++)
			{
				HttpPostedFile hpf = hfc[i];
				if (hpf.ContentLength > 0)
				{
					ls_file_name = ls_file_name + Path.GetFileName(hpf.FileName);	//업로드시 선택한 파일명
					string ls_file_size = (hpf.ContentLength / 1000).ToString(); //파일크기
					string ls_file_ext = Path.GetExtension(hpf.FileName).Remove(0, 1).ToUpper(); //확장자
					string ls_tmp_file_name = ls_file_name; //임시파일명
					string ls_save_path = upload_path + ls_tmp_file_name; //저장경로

					//중복된 이름의 파일이 있으면 (1)을 붙인다.
					int j = 0;
					while (File.Exists(ls_save_path))
					{
						j++;
						ls_tmp_file_name = Path.GetFileNameWithoutExtension(ls_file_name) + "(" + j.ToString() + ")" + Path.GetExtension(ls_file_name);
						ls_save_path = upload_path + ls_tmp_file_name;
					}

					//확장자 검사
					if (ValidationUtil.IsFileExtImg(ls_file_ext))
					{
						//첨부파일을 DB에 저장하기 위해 라벨에 찍어둔다
						lbl_attach_file1.Text = ls_tmp_file_name;
						lbl_attach_file1_size.Text = ls_file_size;

						//파일저장
						hpf.SaveAs(ls_save_path);
					}
					else
					{
						CallMsgBoxInAjax("MSG_ERR_115");	// 업로드할 수 없는 확장자입니다
					}
				}
			}
		}

		//첨부파일삭제
		private void DeleteFile(string ls_file_name, string ls_pk, int li_file_idx, bool lb_db_del, bool lb_list_yn, bool lb_alert)
		{
			string ls_attach_file = FILE_PATH_UPLOAD + ls_file_name;

			//실제 첨부파일삭제
			if (FileUtil.IsFileExist(ls_attach_file))
			{
				File.Delete(ls_attach_file);
			}
			else
			{
				if (lb_alert)
				{
					CallMsgBoxInAjax("MSG_ERR_123");	// 삭제할 파일이 없습니다
				}
			}

			//DB에서 파일정보 삭제
			if (lb_db_del)
			{
				Crd1010m_RT _Crd1010m_RT = new Crd1010m_RT();
				int li_return;

				li_return = _Crd1010m_RT.DeleteAttachFile(ls_pk, li_file_idx);

				//삭제한 파일이 어느것인지에 따라 분기
				switch (li_return)
				{
					case 1:	//첨부파일1 삭제
						lbl_attach_file1.Text = "";
						lbl_attach_file1_size.Text = "";
						ibtn_delete_attach_file1.Visible = false;
						CallMsgBoxInAjax("MSG_INF_012");	// 파일이 삭제되었습니다
						break;
					default:
						CallMsgBoxInAjax("MSG_ERR_125");	// 파일을 삭제할 수 없습니다
						break;
				}
			}

			if (lb_list_yn)
			{
				SearchProcess();
			}
		}

		#endregion

		#region GridView이벤트

		//RowDataBound
		protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			GridView gv = (GridView)sender;

			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				//마우스올렸을 때
				e.Row.Attributes.Add("onmouseover", "overBackground('GridView1', " + (e.Row.RowIndex + 1) + ")");
				e.Row.Attributes.Add("onmouseout", "outBackground('GridView1', 1)");

				//번호
				e.Row.Cells[1].Text = ((li_row_count - ((li_cur_page - 1) * li_page_size)) - e.Row.RowIndex).ToString();

				//이미지
				string ls_card_image = gv.DataKeys[e.Row.RowIndex].Values["Attach_File1"].ToString();
				string src = (string.IsNullOrEmpty(ls_card_image)) ? FILE_PATH_COMMON_IMAGE + "empty.png" : FILE_PATH_UPLOAD_WEB_PATH + ls_card_image;

				e.Row.Cells[2].Text = "<img src=\"" + src + "\" height=\"40\" />";

				switch (e.Row.Cells[15].Text)
				{
					case "Y":
						e.Row.Cells[15].Attributes.Add("class", "color_darkred");
						break;
					case "N":
						e.Row.Cells[15].Attributes.Add("class", "color_gray");
						break;
					default:
						e.Row.Cells[15].Attributes.Add("class", "color_darkred");
						break;
				}
			}
		}
		
		//RowCommand
		protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
		{
			GridView gv = (GridView)sender;
			GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);

			LinkButton lbtn_rc = (LinkButton)GridView1.Rows[row.RowIndex].FindControl("lbtn_rc");

			//row.Cells[0].Text.ToString();//0.체크박스
			h_no.Value						= row.Cells[1].Text.ToString();									//1.번호
																											//2.이미지
			lbl_pk.Text						= gv.DataKeys[row.RowIndex].Values["Seq"].ToString();			//3.Seq
			lbl_card_cd.Text				= row.Cells[4].Text.Trim();										//4.Card_Cd
			txt_card_nm.Text				= lbtn_rc.Text;													//5.Card_Nm (template)
			txt_card_num.Text				= row.Cells[6].Text.Trim();										//6.Card_Num
			txt_cvc_num.Text				= row.Cells[7].Text.Trim();										//7.Cvc_Num
			txt_valid_ym.Text				= row.Cells[8].Text.Trim();										//8.Valid_Ym
			txt_limit_use.Text				= row.Cells[9].Text.Trim();										//9.Limit_Use
			txt_limit_cash.Text				= row.Cells[10].Text.Trim();									//10.Limit_Cash
			ddl_issue_co.SelectedValue		= gv.DataKeys[row.RowIndex].Values["Issue_Co"].ToString();		//11.Issue_Co
																											//12.Issue_Co_Nm
																											//13.Accnt_Nm
			ddl_accnt_num.SelectedValue		= gv.DataKeys[row.RowIndex].Values["Accnt_Num"].ToString();		//14.Accnt_Num
			rbl_use_yn.SelectedValue		= row.Cells[15].Text.Trim();									//15.Use_Yn
			ddl_mass_st_div.SelectedValue	= gv.DataKeys[row.RowIndex].Values["Mass_St_Div"].ToString();	//16.Mass_St_Div
			ddl_mass_st_dt.SelectedValue	= gv.DataKeys[row.RowIndex].Values["Mass_St_Dt"].ToString();	//17.Mass_St_Dt
			ddl_mass_ed_div.SelectedValue	= gv.DataKeys[row.RowIndex].Values["Mass_Ed_Div"].ToString();	//18.Mass_Ed_Div
			ddl_mass_ed_dt.SelectedValue	= gv.DataKeys[row.RowIndex].Values["Mass_Ed_Dt"].ToString();	//19.Mass_Ed_Dt
			ddl_cash_st_div.SelectedValue	= gv.DataKeys[row.RowIndex].Values["Cash_St_Div"].ToString();	//20.Cash_St_Div
			ddl_cash_st_dt.SelectedValue	= gv.DataKeys[row.RowIndex].Values["Cash_St_Dt"].ToString();	//21.Cash_St_Dt
			ddl_cash_ed_div.SelectedValue	= gv.DataKeys[row.RowIndex].Values["Cash_Ed_Div"].ToString();	//22.Cash_Ed_Div
			ddl_cash_ed_dt.SelectedValue	= gv.DataKeys[row.RowIndex].Values["Cash_Ed_Dt"].ToString();	//23.Cash_Ed_Dt
			string ls_attach_file1			= gv.DataKeys[row.RowIndex].Values["Attach_File1"].ToString();		//24.Attach_File1
			string ls_attach_file1_size		= gv.DataKeys[row.RowIndex].Values["Attach_File1_Size"].ToString();	//25.Attach_File1_Size

			//첨부파일1
			if (!String.IsNullOrEmpty(ls_attach_file1) && ls_attach_file1 != "-")
			{
				lbl_attach_file1.Text = ls_attach_file1;
				lbl_attach_file1_size.Text = ls_attach_file1_size;
				ibtn_delete_attach_file1.Visible = true;
			}
			else
			{
				lbl_attach_file1.Text = "";
				lbl_attach_file1_size.Text = "";
				ibtn_delete_attach_file1.Visible = false;
			}
		}		
		
		#endregion

		#region 버튼이벤트

		//검색
		protected void ibtn_search_Click(object sender, EventArgs e)
		{
			SearchProcess();
		}

		//저장
		protected void ibtn_save_Click(object sender, EventArgs e)
		{
			//파일업로드
			UploadFile();
			
			if (global.CheckSaveMode("UPDMS_CRD_INFO", "Seq", lbl_pk.Text.Trim()))
			{
				UpdateProcess();
			}
			else
			{
				InsertProcess();
			}
		}

		//삭제
		protected void ibtn_delete_Click(object sender, EventArgs e)
		{
			StringBuilder sb = new StringBuilder();

			sb.Append("<UPDMS>");

			for (int i = 0; i < GridView1.Rows.Count; i++)
			{
				GridViewRow row = GridView1.Rows[i];
				HtmlInputCheckBox cb = (HtmlInputCheckBox)row.FindControl("cb_check");

				if (cb.Checked)
				{
					string ls_seq = GridView1.DataKeys[i].Values["Seq"].ToString();
					string ls_file_name1 = GridView1.DataKeys[i].Values["Attach_File1"].ToString();	//파일1이름

					// 첨부파일을 먼저 삭제한다.
					DeleteFile(ls_file_name1, ls_seq, 1, false, false, false);
					
					sb.Append("<UPDMS_CRD_INFO>");
					sb.Append("<Seq>" + ls_seq + "</Seq>");
					sb.Append("</UPDMS_CRD_INFO>");
				}
			}
			sb.Append("</UPDMS>");

			DeleteProcess(sb.ToString());
		}

		//엑셀
		protected void ibtn_excel_Click(object sender, EventArgs e)
		{
			SetSearchParameter();

			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_card_nm", typeof(string), kw1);
			lo_dp.AddProperty("ls_card_num", typeof(string), kw2);
			lo_dp.AddProperty("ls_use_yn", typeof(string), kw3);

			using (Crd1010m_NT _Crd1010m_NT = new Crd1010m_NT())
			{
				li_row_count = _Crd1010m_NT.GetSearchCount(lo_dp);
				
				lo_dp.AddProperty("li_st_page", typeof(Int32), 0);
				lo_dp.AddProperty("li_ed_page", typeof(Int32), li_row_count);
				lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

				lo_ds.Merge(_Crd1010m_NT.SelectProcess(lo_dp));
			}
			string fileName = PID + "(" + global.GetMenuTitle(PID, LANG_SET) + ")";
			ExcelUtil.CreateExcelFileX(this.Page, fileName, lo_ds, SetExcelHeaderX(global.GetColumnListByPgmId(PID, LANG_SET)));
		}

		//첨부파일1 삭제
		protected void ibtn_delete_attach_file1_Click(object sender, EventArgs e)
		{
			DeleteFile(lbl_attach_file1.Text, lbl_pk.Text, 1, true, true, true);
		}

		//모두보기
		protected void cb_list_all_CheckedChanged(object sender, EventArgs e)
		{
			SearchProcess();
		}

		#endregion
	}
}
